package com.jdrx.sw.sewage.api.web;

import com.jdrx.platform.commons.rest.beans.dto.IdDTO;
import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.DnbStatisticsDTO;
import com.jdrx.sw.sewage.beans.dto.OperationAnalysisDTO;
import com.jdrx.sw.sewage.beans.dto.StationIdDTO;
import com.jdrx.sw.sewage.beans.dto.WaterQualityMonitorDTO;
import com.jdrx.sw.sewage.beans.vo.*;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/bigdatascreen")
@Api(value = "数据大屏")
public class BigDataScreenApi {

    @Autowired
    private NewsServiceImpl newsServiceImpl;
    @Autowired
    private AlarmServiceImpl alarmServiceImpl;
    @Autowired
    private DeviceServiceImpl deviceServiceImpl;
    @Autowired
    private MaintenanceServiceImpl maintenanceServiceImpl;
    @Autowired
    private ProcessunitServiceImpl processunitServiceImpl;
    @Autowired
    private StationReportAnalysisServiceImpl reportAnalysisServiceImpl;
    @Autowired
    private MedicineAnalysisService medicineAnalysisService;

    @ApiOperation(value = "查询新闻列表")
    @RequestMapping(value = "findList", method = RequestMethod.POST)
    public ResponseVO<List<NewsVO>> findMaintenanceDevList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                           @RequestHeader(Constant.TENANT_ID) String tenantId) {
        return ResponseFactory2.ok(newsServiceImpl.findList());
    }

    @ApiOperation(value = "查询新闻详情")
    @RequestMapping(value = "findNewsById", method = RequestMethod.POST)
    public ResponseVO delete(@RequestHeader(Constant.DATA_NODE) String dataNode,
                             @RequestHeader(Constant.TENANT_ID) String tenantId,
                             @RequestBody @Valid IdDTO dto) throws BizException {
        return ResponseFactory2.ok(newsServiceImpl.selectById(dto));
    }

    @ApiOperation(value = "查询告警数和告警列表")
    @RequestMapping(value = "findAlarmNumAndAlarmList", method = RequestMethod.POST)
    public ResponseVO<Map<String, Object>> findAlarmNumAndAlarmList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                    @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                    @RequestBody @Valid StationIdDTO dto) {
        return ResponseFactory2.ok(alarmServiceImpl.findAlarmNumAndAlarmList(dto));
    }

    @ApiOperation(value = "查询运行时长")
    @RequestMapping(value = "findRunTime", method = RequestMethod.POST)
    public ResponseVO<List<DevRunTimeVO>> findRunTime(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                      @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                      @RequestBody @Valid StationIdDTO dto) {
        return ResponseFactory2.ok(deviceServiceImpl.findRunTime(dto));
    }

    @ApiOperation(value = "资产维护")
    @RequestMapping(value = "assetsMaintain", method = RequestMethod.POST)
    public ResponseVO<Map<String, Integer>> assetsMaintain(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                           @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                           @RequestBody @Valid StationIdDTO dto) {
        return ResponseFactory2.ok(maintenanceServiceImpl.assetsMaintain(dto));
    }

    @ApiOperation(value = "故障分析")
    @RequestMapping(value = "AlarmAnalysis", method = RequestMethod.POST)
    public ResponseVO<Map<String, Integer>> AlarmAnalysis(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                          @RequestBody @Valid StationIdDTO dto) {
        return ResponseFactory2.ok(alarmServiceImpl.AlarmAnalysis(dto));
    }

    @ApiOperation(value = "查询出水信息")
    @RequestMapping(value = "outWater", method = RequestMethod.POST)
    public ResponseVO<Map<String, Double>> outWater(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                    @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                    @RequestBody @Valid StationIdDTO dto) {
        return ResponseFactory2.ok(processunitServiceImpl.outWater(dto));
    }

    @ApiOperation(value = "水质监测")
    @RequestMapping(value = "waterQualityMonitor", method = RequestMethod.POST)
    public ResponseVO<Map<String, Map<Integer, List<WaterQualityVO>>>> waterQualityMonitor(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                                           @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                                           @RequestBody @Valid WaterQualityMonitorDTO dto) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.waterQualityMonitor(dto));
    }

    @ApiOperation(value = "药耗统计")
    @RequestMapping(value = "drugConsStatistics", method = RequestMethod.POST)
    public ResponseVO<Map<String, List<DrugConsStatisticsVO>>> drugConsStatistics(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                                  @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                                  @RequestBody @Valid StationIdDTO dto) throws Exception {
        return ResponseFactory2.ok(medicineAnalysisService.drugConsStatistics(dto));
    }

    @ApiOperation(value = "能耗统计")
    @RequestMapping(value = "dnbStatistics", method = RequestMethod.POST)
    public ResponseVO<Map<Integer, List>> dnbStatistics(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                        @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                        @RequestBody @Valid DnbStatisticsDTO dto) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.dnbStatistics(dto));
    }

    @ApiOperation(value = "日出水达标率")
    @RequestMapping(value = "operationAnalysis", method = RequestMethod.POST)
    public ResponseVO<Map<String, Double>> operationAnalysis(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                             @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                             @RequestBody @Valid OperationAnalysisDTO dto) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.operationAnalysis(dto));
    }

    @ApiOperation(value = "处理水量")
    @RequestMapping(value = "handleWater", method = RequestMethod.POST)
    public ResponseVO<List<ReportAnalysisVO>> handleWater(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                          @RequestBody @Valid DnbStatisticsDTO dto) {
        return ResponseFactory2.ok(reportAnalysisServiceImpl.handleWater(dto));
    }
}
